package com.dxysun.springboot.config;

import java.util.List;

import com.dxysun.springboot.convert.MyCustomHttpMessageConverter;
import com.dxysun.springboot.convert.MyMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.dxysun.springboot.interceptor.MyInterceptor;
import com.dxysun.springboot.reslover.UserParamResolver;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer
{
	@Override
	public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
	{
		resolvers.add(new UserParamResolver());
	}


/*	@Bean
	public MyInterceptor myInterceptor()
	{
		return new MyInterceptor();
	}*/

	@Override
	public void addInterceptors(InterceptorRegistry registry)
	{
		//拦截处理操作的匹配路径
		//放开静态拦截
		registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**") //拦截所有路径
//				.excludePathPatterns("/login", "/", "/exit", "/get_cpacha")//排除路径
//				.excludePathPatterns("/xadmin/**")
		;//排除静态资源拦截

	}

	/*@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//		MyCustomHttpMessageConverter converter = new MyCustomHttpMessageConverter();
//        converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED));
//		converters.add(converter);
		converters.add(0, myMessageConverter());
//		converters.add(new CustomFormHttpMessageConverter());
//		super(converters);
	}*/

	/**
	 * 添加自定义的httpMessageConverter
	 */
/*	@Override
	public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//		converters.add(messageConverter());
		converters.add(myMessageConverter());
	}*/

//	@Bean
	public MyCustomHttpMessageConverter messageConverter(){
		return new MyCustomHttpMessageConverter();
	}

//	@Bean
	public MyMessageConverter myMessageConverter(){
		return new MyMessageConverter();
	}

}
